package com.sc.admin.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sc.admin.mapper.RoleMenuPrivMapper;
import com.sc.admin.pojo.RoleMenuPriv;

@Service
public class RoleMenuPrivServiceImpl implements RoleMenuPrivService {
	@Autowired
	private RoleMenuPrivMapper roleMenuPrivMapper;

	@Override
	public List<RoleMenuPriv> getRoleMenuPrivByRoleId(int roleId) {
		return roleMenuPrivMapper.selectByRoleId(roleId);
	}

	@Override
	public void deleteRoleMenuPrivByRoleId(int roleId) {
		roleMenuPrivMapper.deleteByRoleId(roleId);
	}

	@Override
	public void addRoleMenuPriv(int roleId, String menuIds) {
		roleMenuPrivMapper.deleteByRoleId(roleId);
		String[] ids = menuIds.split(",");
		for(String id : ids) {
			RoleMenuPriv record = new RoleMenuPriv();
			record.setMenuId(Integer.parseInt(id));
			record.setRoleId(roleId);
			roleMenuPrivMapper.insertSelective(record );
		}
	}

}
